<template>
	<view>
		<scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll-Y" @scrolltoupper="upper" @scrolltolower="lower" @scroll="scroll" style="height: 1250rpx;width: 750rpx;" :lower-threshold="lower_threshold" refresher-enabled="true" :refresher-triggered="triggered" @refresherrefresh="onRefresh" :refresher-threshold="100" @refresherpulling="pulling" refresher-background="#FF7300">
			<view v-if="list_shuju_.length != 0">
				<view style="margin: 30rpx 27.77rpx 27.77rpx 27.77rpx;">
					<view v-for="(itme,index) in list_shuju_" :key="index" style="width: 695rpx;box-sizing: border-box;padding: 30rpx;background: #FFFFFF;border-radius: 25rpx;margin-bottom: 20rpx;border: 0.5rpx solid #BEBEBE;position: relative;">
						<view style="padding: 6rpx 10rpx;display: flex;justify-content: center;align-items: center;border-radius: 28rpx;font-size: 23rpx;border: 1rpx solid #FF7300;left: 540rpx;top: 30rpx;position: absolute;color:#FF7300 ;" v-if="list_shuju == 0" @tap.stop="zhuanchang(itme)">
							<text>{{content}}</text>
						</view>
						<view style="display: flex;align-items: center;" >
							<view>
								<image :src="itme.map.mechanismEntity.mechanism_logo" style="width: 70rpx;height: 70rpx;border-radius: 50%;border: 0.5rpx solid #BEBEBE;"></image>
							</view>
							<view style="margin-left: 15rpx;font-size: 25rpx;color: #BEBEBE;letter-spacing: 1rpx;">
								<text>{{itme.map.mechanismEntity.mechanism_name}}</text>
								<image :src="zhijian" style="width: 15rpx;height: 20rpx;vertical-align: middle;margin-left: 10rpx;"></image>
							</view>
						</view>
						<view style="display: flex;margin-top: 18rpx;" @tap.stop="gokecheng(itme.map.masterSetPriceEntity,itme.map.mechanismEntity)">
							<view>
								<image :src="itme.map.masterSetPriceEntity.face_url" style="width: 170rpx;height: 170rpx;border-radius: 9rpx;border: 0.5rpx solid #BEBEBE;"></image>
							</view>
							<view style="margin-left: 25rpx;">
								<view style="font-size: 32rpx;font-weight: bold;">{{itme.new_title}}</view>
								<view style="font-size: 25rpx;color: #BEBEBE;margin-top: 15rpx;">{{itme.map.masterSetPriceEntity.label}}</view>
							</view>
						</view>
						<view style="font-size: 28rpx;color: #4C4C4C;display: flex;position: absolute;left: 480rpx;top: 270rpx;align-items: center;">
							<view >实付款</view>
							<view style="color: #FF7300;display: flex;align-items: center;">
								<text>￥</text>
								<text style="font-size: 35rpx;font-weight: bold;">{{itme.amount}}</text>
							</view>
						</view>
					</view>
				</view>
			</view>
		</scroll-view>
		<van-popup position="bottom" :show="isshow_popup" :round="round" close-on-click-overlay>
			<view style="height: 500rpx;width: 750rpx;box-sizing: border-box;padding: 20rpx;background: #FFFFFF;position: relative;">
				<view style="font-size: 40rpx;font-weight: bold;width: 100%;text-align: center;">微信支付</view>
				<view style="position: absolute;width: 50rpx;height: 40rpx;background: #E4E4E4;font-size: 20rpx;line-height: 40rpx;text-align: center;border-radius: 20rpx;top: 30rpx;left: 670rpx;color: #939393;" @tap="guani">关闭</view>
				<view style="height: 300rpx;width: 100%;display: flex;justify-content: center;align-items: center;color: #ED4949;font-size: 55rpx;">
					<text >￥</text>
					<text style="font-weight: bold;">{{zhifu_money}}</text>
				</view>
				<button type="primary" style="background:#FF7300 ;" @tap="tianqi">确定支付</button>
			</view>
		</van-popup>
	</view>
</template>
<script>
	export default {
		props:{
			list_shuju: Number
		},
		data(){
			return {
				list_shuju_: [],
				user_id: "",
				currentPage: 1,
				is_one_time_payment: false ,
				scrollTop: 0,
				biaoji_shu: 1,
				lower_threshold: 100,
				content: "",
				status: "",
				finished: false,
				course_num: 1,
				study_type: "",
				data_list: {},
				triggered: false,
				background_list: "#BEBEBE",
				num: 1,
				isshow_popup: false,
				round: true,
				zhifu_money: "",
				closeable: true,
				shuju_obj: {},
				zhijian: "http://img.curiousmore.com/578648"
			}
		},
		methods:{
			async	xiangqing(index){
					const res = await this.$myRequest({
						url: "/userStudyCard/queryPayInfo",
						data: {
							id: index.user_study_card_id
						}
					})
					this.zhifu_money = res.data.payNum
				},
				guani(){
					this.isshow_popup = false
				},
				gokecheng(itme,index){
					let data = {
						data: index
					}
					let itmes = Object.assign(itme,data)
					uni.navigateTo({
						url: '/pages/World/classChannel/classChannel?num=' + encodeURIComponent(JSON.stringify(itmes))
					})
				},
				onRefresh(){
					this.triggered = true
					this.currentPage = 1
					this.list_shuju_ = []
					this.shuju(this.data_list)
				},
				lower(){
					if(this.biaoji_shu == 1){
						this.currentPage++
						this.shuju()
					}
				},
		async	shuju(itme){
				uni.showLoading({
				    title: '加载中'
				})
				const res = await this.$myRequest({
					url: "/rechargerecord/queryMechanismList",
					data: itme
				})
				if(res.code == 0){
					if(res.data.length < 10){
						this.biaoji_shu = 2
					}
					if(res.data.length > 0){
						res.data.forEach((itme) => {
							itme.new_title = "【" + itme.map.masterSetPriceEntity.course_num + "节" +  "】" + itme.map.masterSetPriceEntity.title
						})
					}
					if(this.list_shuju_.length == res.data){
						this.list_shuju_ = res.data
					}else{
						this.list_shuju_ = this.list_shuju_.concat(res.data)
					}
					setTimeout(() => {
						if(this.list_shuju_.length == 0){
							uni.showToast({
								title: '暂无数据',
								duration: 2000,
								icon:"none"
							})
						}
					},100)
				}
				setTimeout(() => {
					this.triggered = false
				},10)
				uni.hideLoading()
			},
			zhuanchang(itme){
				this.isshow_popup = true
				this.shuju_obj = itme
				
				this.xiangqing(itme)
			},
			tianqi(){
				uni.login({
					success: (res) => {
						this.zhifu(this.shuju_obj,res.code)
					}
				})
			},
		async	zhifu(itme,code){
				let me = this
				const resl = await me.$myRequest({
					url: "/pay/payPre",
					methed: "post",
					header: {
						'content-type':'application/json'
					},
					data: {
						user_id: me.user_id,
						rcharge_type: "specialty_sheets",
						source: " teach_paypal",
						course_num: 1,
						master_id: itme.master_id,
						rcharge_abstract: "微信小程序转长单",
						studycard_id: itme.studycard_id,
						study_type: "mechanism_offline",
						is_one_time_payment: true,
						user_study_card_id: itme.user_study_card_id,
						paying_for_identity: "user",
						pay_type: "wx",
						mechanism_id: itme.mechanism_id,
						rcharge_valid: code
					}
				})
				if(resl.code == 0){
					uni.requestPayment({
						timeStamp: resl.data.timeStamp,
						nonceStr: resl.data.nonceStr,
						package: resl.data.package,
						signType: 'MD5',
						paySign: resl.data.paySign,
						success: (re) => {
							uni.showToast({
								title: "成功"
							})
							this.shuju(this.data_list)
						}
					})
				}else{
					uni.showToast({
						title: resl.message
					})
				}
			}
		},
		onLoad() {
			try{
				this.user_id = uni.getStorageSync('userif_list').user_id
			}catch(e){}
			this.list_shuju_ = []
			if(this.list_shuju == 0){
				this.content = "转全额"
				this.is_one_time_payment = false
				this.finished = false
				let data = {
					type: "study_card",
					user_id: this.user_id,
					finished: false,
					is_one_time_payment: this.is_one_time_payment,
					pageSize: 10,
					currentPage: this.currentPage,
					study_type: "mechanism_offline",
					status: 1
				}
				this.data_list = data
				this.shuju(this.data_list)
			}else if(this.list_shuju == 1){
				let data = {
					type: "study_card",
					user_id: this.user_id,
					finished: true,
					is_one_time_payment: false,
					pageSize: 10,
					currentPage: this.currentPage,
					study_type: "mechanism_offline",
					course_num: 1,
					source: "wx"
				}
				this.data_list = data
				this.shuju(this.data_list)
			}else if(this.list_shuju == 2){
				let data = {
					rcharge_type: "specialty_sheets",
					user_id: this.user_id,
					finished: true,
					is_one_time_payment: true,
					pageSize: 10,
					currentPage: this.currentPage
				}
				this.data_list = data
				this.shuju(this.data_list)
			}else{
				let data = {
					study_type: "mechanism_offline",
					user_id: this.user_id,
					finished: true,
					is_one_time_payment: true,
					pageSize: 10,
					currentPage: this.currentPage
				}
				this.data_list = data
				this.shuju(this.data_list)
			}
			this.triggered = false
			
		},
		onShow(){
			
		}
	}
</script>
<style lang="scss" scoped>
	
</style>